﻿#ifndef DISPATCHERTHREAD_H
#define DISPATCHERTHREAD_H

#include <QObject>
#include<QThread>
#include<QTcpSocket>
#include<QJsonObject>
#include <qmutex.h>
#include "DataBase/dboperation.h"
//struct UserInfo       //待存放的数据结构//
//{
//    QString UserId;
//    QString UserName;
//    QString UserSex;
//    QString UserAge;
//};
class DispatcherThread : public QThread
{
    Q_OBJECT
public:
    DispatcherThread(QObject *parent = 0);
    ~DispatcherThread();
    void setSocketDescriptor(qintptr sockFd);
    QString getAddressIp() const;
    void setAddressIp(const QString &value);

public slots:
    void readData();
    void slotDisconnected();
    void writeData(int sptr,QJsonObject json);
signals:
    void closeMe(DispatcherThread *thread);
    void updateMsg(QString ip_port, QString msg);

    void updateMsg(QJsonObject json);
    void updateClient(QString address);
protected:
    void run();
private:
    int socketDescriptor;
    QString addressIp;
    QTcpSocket *m_tcpSocket;
    QMutex mutex;
};

#endif // DISPATCHERTHREAD_H
